#pragma once
#include "RBTree.h"


namespace xyx
{
	template<class K, class V>
	class map
	{	
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::const_iterator const_iterator;

		iterator begin() 
		{
			return _tree.begin();
		}

		iterator end() 
		{
			return _tree.end();
		}

		const_iterator begin() const
		{
			return _tree.begin();
		}

		const_iterator end() const
		{
			return _tree.end();
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> p = insert(make_pair(key, V()));
			return p.first->second;
		}

		pair<iterator, bool> insert(const pair<K, V> kv)
		{
			return _tree.Insert(kv);
		}


	private:
		RBTree<K, pair<const K, V>, MapKeyOfT> _tree;
	};
}